home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / src / haeberli / impression / sssample.c < prev    next >
C/C++ Source or Header  |  1994-08-01  |  2KB  |  105 lines

  1. /*
  2.  * Copyright 1991, 1992, 1993, 1994, Silicon Graphics, Inc.
  3.  * All Rights Reserved.
  4.  *
  5.  * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
  6.  * the contents of this file may not be disclosed to third parties, copied or
  7.  * duplicated in any form, in whole or in part, without the prior written
  8.  * permission of Silicon Graphics, Inc.
  9.  *
  10.  * RESTRICTED RIGHTS LEGEND:
  11.  * Use, duplication or disclosure by the Government is subject to restrictions
  12.  * as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
  13.  * and Computer Software clause at DFARS 252.227-7013, and/or in similar or
  14.  * successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
  15.  * rights reserved under the Copyright Laws of the United States.
  16.  */
  17. /*
  18.  *    sssample - 
  19.  *        Sample an image with a given sample set.
  20.  *
  21.  *            Paul Haeberli - 1988
  22.  */
  23. #include "stdio.h"
  24. #include "ss.h"
  25. #include "texture.h"
  26.  
  27. #define COLOR        1
  28. #define DIRECTION    2
  29. #define POSITION    4
  30. #define SIZE        8
  31.  
  32. main(argc,argv)
  33. int argc;
  34. char **argv;
  35. {
  36.     sampleset *iss, *oss;
  37.     TEXTURE *tm;
  38.     int i;
  39.  
  40.     if( argc<4 ) {
  41.     fprintf(stderr,"usage: sssample in.ss out.ss inimage [-d] [-s]\n");
  42.     exit(1);
  43.     } 
  44.     iss = ssfromfile(argv[1]);
  45.     tm = tmopen(argv[3]);
  46.     if(!tm) {
  47.     fprintf(stderr,"sssample: can't open texture map\n");
  48.     exit(1);
  49.     } 
  50.     oss = ssnew();
  51.     if(argc>4)
  52.     sssampledir(iss,oss,tm);
  53.     else
  54.     sssamplergb(iss,oss,tm);
  55.     sstofile(argv[2],oss);
  56. }
  57.  
  58. sssampledir(iss,oss,tm)
  59. sampleset *iss, *oss; 
  60. TEXTURE *tm;
  61. {
  62.     sample *s, *ns;
  63.     int imag, bimag;
  64.     int size, dir;
  65.     vect p, c;
  66.  
  67.     s = iss->head;
  68.     while(s) {
  69.     ns = sclone(s);
  70.     p.x = ns->xpos/(float)POSSCALE;
  71.     p.y = ns->ypos/(float)POSSCALE;
  72.     tmsample(tm,&p,&c);
  73.     dir = (c.x)*255;
  74.     if(dir>255)
  75.         dir -= 256;
  76.     ns->SAMPLE_DIR = dir;
  77.     addsample(oss,ns);
  78.     s = s->next;
  79.     }
  80. }
  81.  
  82. sssamplergb(iss,oss,tm)
  83. sampleset *iss, *oss; 
  84. TEXTURE *tm;
  85. {
  86.     sample *s, *ns;
  87.     int imag, bimag;
  88.     int size;
  89.     vect p, c;
  90.  
  91.     s = iss->head;
  92.     while(s) {
  93.     ns = sclone(s);
  94.     p.x = ns->xpos/(float)POSSCALE;
  95.     p.y = ns->ypos/(float)POSSCALE;
  96.     tmsample(tm,&p,&c);
  97.     ns->r = 255*c.x;
  98.     ns->g = 255*c.y;
  99.     ns->b = 255*c.z;
  100.     addsample(oss,ns);
  101.     s = s->next;
  102.     }
  103. }
  104.  
  105.